using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace GameEditor.Common.Designer
{
    public class ImageWindow : Window
    {
        private Image image;

        public Image Image
        {
            get { return image; }
            set { image = value; }
        }
        private Nullable<Rectangle> imageRegion = null;

        public Nullable<Rectangle> ImageRegion
        {
            get { return imageRegion; }
            set { imageRegion = value; }
        }



        public ImageWindow(DesignerPanel panel)
            : base(panel)
        {
        }
        public ImageWindow(DesignerPanel panel, Image image)
            : base(panel)
        {
            this.image = image;
        }
        public ImageWindow(DesignerPanel panel, Image image,Nullable<Rectangle> imageRegion)
            : base(panel)
        {
            this.image = image;
            this.imageRegion = imageRegion;
        }
        public override void OnDraw(System.Drawing.Graphics g)
        {
            base.OnDraw(g);
            Rectangle trect = TransformedGeometry;
            if (image != null)
            {
                if (imageRegion == null)
                {
                    //draw the entire image
                    g.DrawImage(image, trect);
                }
                else
                {
                    //draw only a part of it
                    DrawRect(g, image, trect, imageRegion.Value);
                }
            }
            else
            {
                //Draw the invalid window
                DrawInvalidFrame(g,trect);
            }
            base.OnDraw(g);
        }

    }
}
